/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modeladesktop.algoritmo;

//import org.apache.commons.math.MathException;

import modeladesktop.gui.Analisis;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.TDistribution;
import org.apache.commons.math.distribution.TDistributionImpl;

//import org.apache.commons.math.distribution.TDistribution;
//import org.apache.commons.math.distribution.TDistributionImpl;

/**
 *
 * @author ddhernan
 */
public class TestsHipotesis {

    private double t;
    private double[] betas;
    Analisis analizado;
    
    public TestsHipotesis(Analisis analizado,double levelsignificance,int degress) throws MathException{
        this.betas=analizado.coeficientesEcuacion;
        this.analizado=analizado;
		this.calcT(levelsignificance, degress);
    }
    public double[][] testBEqualZero(Analisis analizado,double levelsignificance,int degress) throws MathException{
        
         double[][] testBethas=new double[betas.length][2];
         //this.calcT(levelsignificance, degress);

         for(int i=1;i<testBethas.length;i++){
            testBethas[i][0]=(analizado.coeficientesEcuacion[i]-0)/analizado.sb1;
            testBethas[i][1]=this.testBetaequalZero(testBethas[i][0],this.getT());
            
         }
         analizado.testBethas=testBethas;
         return testBethas;

    }
	public double testBetaequalZero(double t,double tcalculada){
        return (t>tcalculada&&t<tcalculada)?1:0;
    }
    public void print(Analisis analizado){
        System.out.println("Tcalculada "+this.getT());
       for(int i=1;i<analizado.testBethas.length;i++){
            System.out.println("Beta "+analizado.coeficientesEcuacion[i]+" Tcalculada "+analizado.testBethas[i][0]+" Prueba "+analizado.testBethas[i][1]);
       }
    }
  

    public void calcT(double levelsignificance,int degress) throws MathException{
        TDistribution tdist = new TDistributionImpl(degress);
        this.setT(-tdist.inverseCumulativeProbability(levelsignificance/2));

    }
    public double getT() {
        return t;
    }

    public void setT(double t) {
        this.t = t;
    }


}
